//
//  TagCell.m
//  FKGW
//
//  Created by song ce on 2017/2/27.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "TagCell.h"
#import "UIView+Extend.h"

@implementation TagCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self addNotifactions];
   //重新设置自身的宽度
    self.width = Main_Screen_Width*.75;
    //设置键盘类型为数字键盘
    self.minPriceTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.maxPriceTextField.keyboardType = UIKeyboardTypeNumberPad;
    //添加实时监测输入内容的变化
    [self.minPriceTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [self.maxPriceTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}

//添加通知
-(void)addNotifactions{
    //控制器将要消失 收回键盘通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(callBackKeyBoard) name:@"selectViewWillDisappear" object:nil];
    //接收通知，重置填写的内容
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(re_set) name:@"clearInputText" object:nil];

}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter ]removeObserver:self];
}

#pragma mark - 内容改变事件
- (void)textFieldDidChange:(UITextField *)textField{
    DLog(@"%@",textField.text);
    if([textField isEqual:self.minPriceTextField]){
        if(self.minBlock){
            self.minBlock(textField.text);
        }
    }
    
    if([textField isEqual:self.maxPriceTextField]){
        if(self.maxBlock){
            self.maxBlock(textField.text);
        }
    }
}

- (void)callBackKeyBoard{
    [self endEditing: YES];
}

-(void)re_set{
    self.minPriceTextField.text = @"";
    self.maxPriceTextField.text = @"";
    [self endEditing: YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
